package com.free.config;

import com.free.common.entity.ReqInfoDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author hao.ding@insentek.com
 * @date 2021-10-29 10:18
 */
@Configuration
public class HeartBeatConfig {
    @Autowired
    private ServerConfig serverConfig;

    @Value("${spring.application.name}")
    private String serviceName;

    @Bean(value = "heartBeat")
    public ReqInfoDto heartBeat() {
        return requestParameter();
    }

    public ReqInfoDto requestParameter() {
        return requestParameter(null);
    }

    public ReqInfoDto requestParameter(Long renewalDuration) {
        ReqInfoDto reqInfoDto = new ReqInfoDto();
        //获取ip和端口号码
        String appHostAndPort = serverConfig.getAppHostAndPort();
        reqInfoDto.setServiceName(serviceName);
        reqInfoDto.setServiceAddress(appHostAndPort);
        if (renewalDuration != null) {
            reqInfoDto.setRenewalDuration(renewalDuration);
        }
        return reqInfoDto;
    }
}
